package com.guoyh.bilui.ext

import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.guoyh.bilui.title.STitleBar

/**
 * @CreateDate: 7/19/21 8:18 PM
 * @Author: guoyh
 * @Description: java类作用描述
 */
fun STitleBar.init(leftClick: () -> Unit, rightClick: () -> Unit = {}) {
    setOnLeftButtonClickListener(object : STitleBar.OnLeftButtonClickListener {
        override fun onLeftButtonClick(v: View) {
            leftClick.invoke()
        }
    })
    setOnRightButtonClickListener(object : STitleBar.OnRightButtonClickListener {
        override fun OnRightButtonClick(v: View) {
            rightClick.invoke()
        }
    })
}

fun STitleBar.init(activity: FragmentActivity, rightClick: () -> Unit = {}) {
    setOnLeftButtonClickListener(object : STitleBar.OnLeftButtonClickListener {
        override fun onLeftButtonClick(v: View) {
            activity.finish()
        }
    })
    setOnRightButtonClickListener(object : STitleBar.OnRightButtonClickListener {
        override fun OnRightButtonClick(v: View) {
            rightClick.invoke()
        }
    })
}

fun STitleBar.init(fragment: Fragment, rightClick: () -> Unit = {}) {
    setOnLeftButtonClickListener(object : STitleBar.OnLeftButtonClickListener {
        override fun onLeftButtonClick(v: View) {
            fragment.activity?.finish()
        }
    })
    setOnRightButtonClickListener(object : STitleBar.OnRightButtonClickListener {
        override fun OnRightButtonClick(v: View) {
            rightClick.invoke()
        }
    })
}